package com.hx.login.interceptor;

import com.hx.common.domain.MiaoshaUser;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author wonghiu
 * @Date 2021/6/5 10:29
 * @Version 1.0.1
 */
@Component
public class AuthInterceptor implements HandlerInterceptor
{
    public static ThreadLocal<MiaoshaUser> loginUser = new ThreadLocal<>();
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
    {
        MiaoshaUser attribute = (MiaoshaUser) request.getSession().getAttribute("loginUser");
        System.out.println("拦截到："+attribute);
//        if (attribute!=null){
//            loginUser.set(attribute);
//            return true;
//        }else {
//            //没登录就去登录
//            request.getSession().setAttribute("msg","请先进行登录");
//            response.sendRedirect("http://localhost:8081/login/to_login");
//            return false;
//        }
        return true;
    }
}